import { Asset, resources, SpriteFrame, AssetManager } from 'cc';

// 加载resources文件夹的资源
export const loadResource = async (path: string): Promise<Asset> => {
    return new Promise((resolve, reject) => {
        resources.load(path, (err, prefab) => {
            if (err) {
                reject(err);
            } else {
                resolve(prefab);
            }
        });
    });
};

export const loadSpriteFrameDir = async (
    dir: string,
    onProgress?: (finished: number, total: number, item: AssetManager.RequestItem) => void
): Promise<SpriteFrame[]> => {
    return new Promise<SpriteFrame[]>((resolve, reject) => {
        resources.loadDir(dir, SpriteFrame, onProgress, (err, assets) => {
            if (err) {
                reject(err);
            } else {
                resolve(assets);
            }
        });
    });
};
